﻿using Microsoft.Azure.Documents.Client;
using Newtonsoft.Json;

namespace WebDocDB.DocumentDBManager.Extensions
{
    public static class FeedResponseExtensions
    {
        public static string ToFormattedJsonString(this FeedResponse<dynamic> feedResponse)
        {
            string json = "[";
            int index = 0;
            foreach (dynamic r in feedResponse)
            {
                index++;
                json += r.ToString();
                if (index == feedResponse.Count)
                {
                    json += "]";
                }
                else
                {
                    json += ",";
                }
            }

            var objects = JsonConvert.DeserializeObject(json);
            json = JsonConvert.SerializeObject(objects, Formatting.Indented);

            return json;
        }
    }
}